package org.smr.ministore.controller;

import javax.annotation.Resource;

import org.apache.commons.lang3.ObjectUtils;
import org.blade.msg.Message;
import org.blade.utils.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smr.ministore.entities.Route;
import org.smr.ministore.service.RouteService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller("RouteController")
public class RouteController {


    private static final Logger logger = LoggerFactory.getLogger(RouteController.class);

	@Resource
	private RouteService service;
	
	/**
	 * 保存编辑后的Route信息
	 * @param route
	 * @return
	 */
	@ResponseBody
	@RequestMapping(method = RequestMethod.PATCH, value = "/Route/edit")
	public Message modify(@RequestBody Route route){
		Message msg = new Message();

		Route persistentRoute = service.queryById(route.getId());
		if(ObjectUtils.notEqual(persistentRoute, null)){
			msg.setStatus(service.updateById(route));
		}else{
			msg.setStatus(service.save(route));
		}
		return msg;
	}

	
	/**
	* 跳转到列表查询Route
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value = "/Route/list-page")
	public String toList(){
		return "/Route/Route-list";
	}

	/**
	*  根据id查询Route
	* @return
	*/
	@ResponseBody
	@RequestMapping(method = RequestMethod.GET, value = "/Route")
	public Route get( String id ){
		return service.queryById(id);
	}


    /**
	 * 分页查询Route信息
	 * @param Route
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/Route/list")
	public Pager<Route> list(@RequestBody Route Route , long pageSize, long pageNum ){

		return service.paginate(Route, pageSize, pageNum);

	}
	
	
	/**
	 * 根据ID删除Route信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value = "/Route/remove",method = RequestMethod.DELETE)
	public Message remove( String id){
		
		Message msg = new Message();
		msg.setStatus(service.deleteById(id));
		return msg;
	}

}
